package com.igeek.javase.ch04.person;

/*
 *@author wangpeng
 *2023/7/13 10:30
 *@description TODO
 */
public class Person {
    String name;
    int age;
    boolean gender;
    Person partner;

    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public void marry(Person p) {
        if (this.gender == p.gender) {
            System.out.println("同性不能结婚！");
        } else if (this.age < 24 && this.gender) {
            System.out.println("男方未达到结婚年龄！");
        } else if (this.age < 22 && !this.gender) {
            System.out.println("女方未达到结婚年龄！");
        } else if (this.partner != null || p.partner != null) {
            System.out.println("某一方已婚！");
        } else {
            this.partner = p;
            p.partner = this;
            System.out.println("恭喜" + this.name + "和" + p.name + "结婚！");
        }
    }
}
